<!--
 * @Author: your name
 * @Date: 2021-12-22 14:19:25
 * @LastEditTime: 2022-02-09 16:19:02
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \xy-web-xiaoxi\public\onlyoffice\studyDocumentPDF.html
-->
<html>
<header>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <style>
    * {
      margin: 0px;
    }

    body {
      margin: 0px;
    }

    .timer {
      position: absolute;
      height: 32px;
      line-height: 32px;
      /* top: 5px; */
      left: 60%;
      margin-left: 150px;
      font-size: 12px;
      color: #fff;
      display: flex;
    }

    #timer {
      display: none;
    }

    .a {
      font-size: 12px;
      margin-left: 30px;
      text-decoration: none;
      color: #fff;
    }
  </style>
</header>
<div class="timer">
  <div align="center" id="countdown">
    <span>00</span>:<span>00</span>
    <input id='timer' type="button" value="开始" />
    <a class="a" href="" onclick="close_window()">退出自学</a>
  </div>

</div>

<body>

  <div class="form">
    <iframe width="100%" height="100%" src="http://localhost:30001/404" name="iframe1">

    </iframe>
  </div>
</body>

</html>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script type="text/javascript">
  var newurl = ''
  newurl = getUrlParam('urldata')
  $(function () {
    var url = newurl + '/api/eim/document_coa/get_coa_by_pdf'
    var documentId = getUrlParam('documentId')
    if (documentId == null) {
      alert("未检测到文档标识")
      return
    }
    url = url + "?documentCoaId=" + documentId
    $("iframe").attr("src", url)
  })


  /**
   * 获取地址栏信息
   * @param name 参数名称
   * @returns {string| 参数值}
   */
  function getUrlParam(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
    var r = window.location.search.substr(1).match(reg);  //匹配目标参数
    if (r != null) return unescape(r[2]); return null; //返回参数值
  }


  window.onload = function () {

    var oCountDown = document.getElementById("countdown");
    var aInput = oCountDown.getElementsByTagName("input")[0];
    var timer = null;
    aInput.onclick = function () {
      this.className == "" ? (timer = setInterval(updateTime, 1000), updateTime()) : (clearInterval(timer));
      this.className = this.className == '' ? "cancel" : '';
    };
    function format(a) {
      return a.toString().replace(/^(\d)$/, '0$1');
    }
    function updateTime() {
      var aSpan = oCountDown.getElementsByTagName("span");
      var oRemain = aSpan[0].innerHTML.replace(/^0/, '') * 60 + parseInt(aSpan[1].innerHTML.replace(/^0/, ''));
      // if (oRemain <= 0) {
      //     clearInterval(timer);
      //     return;
      // }
      oRemain++;
      aSpan[0].innerHTML = format(parseInt(oRemain / 60));
      oRemain %= 60;
      aSpan[1].innerHTML = format(parseInt(oRemain));
      var S = aSpan[1].innerHTML
      var M = aSpan[0].innerHTML
      TimeSum = Number(M * 60) + Number(S)
      // console.log(TimeSum,'oRemain');
    }
    // 加上此句即可。
    aInput.click();
  }



  let iframe = document.getElementById('iframe1')
  console.log(iframe, '64646464664646');


  function close_window() {

    var lessonType = Number(getUrlParam('type')) || 1
    var lessonName = conf.document.title
    var lessonId = getUrlParam('documentId')
    var token = getUrlParam('token')
    var data = { lessonType: lessonType, lessonName: lessonName, lessonId: lessonId, learnDuration: TimeSum }
    var confirms = confirm("你查看的网页正在试图关闭窗口。是否关闭此窗口")
    if (confirms) {
      $.ajax({
        url: newurl + '/api/ts/learn_record/save',
        type: 'post',
        data: JSON.stringify(data),
        cache: false,
        async: false,
        headers: {
          "Authorization": token,
          'Content-Type': 'application/json'  //multipart/form-data;boundary=--xxxxxxx   application/json
        },
        success: function (data) {
          console.log(data, '64646464646');
          window.close("OpenWindow.html", "_self");//火狐浏览器不支持关闭
        }
      })

    }
    else {
      alias('wwwwwwwwww')
      //不执行任何操作
    }
  }

</script>